package mapper;

import BO.ChooseAnswerViewBO;
import BO.EncodeAnswerViewBO;
import BO.FillAnswerViewBO;
import BO.JudgeAnswerViewBO;
import DO.WorkAnswerChooseDO;
import DO.WorkAnswerEncodeDO;
import DO.WorkAnswerFillAnswerDO;
import DO.WorkAnswerJudgeDO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WorkAnswerMapper {

    /**
     * 查询答案
     */

    /**
     * 查询选择题答案
     * @param chooseId
     * @return
     */
    @Select("select answer from choose_question where id = #{chooseId}")
    String getChooseAnswerById(Integer chooseId);

    /**
     * 查询判断题答案
     * @param judgeId
     * @return
     */
    @Select("select answer from judge_question where id = #{judgeId}")
    Integer getJudgeAnswerById(Integer judgeId);

    /**
     * 查询填空题答案
     * @param fillEmptyId
     * @return
     */
    @Select("select answer from fill_empty_answer where fill_empty_id = #{fillEmptyId} order by `order`")
    List<String> getFillEmptyAnswerById(Integer fillEmptyId);


    /**
     * 保存答案
     */

    /**
     * 保存选择题答案
     */
    void saveChooseAnswer(List<WorkAnswerChooseDO> answerChooseDOList);

    /**
     * 保存判断题答案
     * @param workAnswerJudgeDOList
     */
    void saveJudgeAnswer(List<WorkAnswerJudgeDO> workAnswerJudgeDOList);

    /**
     * 保存填空题答案
     * @param workAnswerFillAnswerDOList
     */
    void saveFillEmptyAnswer(List<WorkAnswerFillAnswerDO> workAnswerFillAnswerDOList);

    /**
     * 保存编程题答案
     * @param workAnswerEncodeDOList
     */
    void saveEncodeAnswer(List<WorkAnswerEncodeDO> workAnswerEncodeDOList);


    /**
     * 查询学生已经保存的答案
     */

    /**
     *
     * @param userId
     * @param workId
     * @return
     */
    @Select("select student_answer,right_answer,is_right from work_answer_choose where work_id = #{workId} and user_id =#{userId}")
    List<ChooseAnswerViewBO> getStudentAnswerChooseViewById(Integer userId, Integer workId);

    /**
     * 查询判断题答案
     * @param userId
     * @param workId
     * @return
     */
    @Select("SELECT student_answer,right_answer,is_right from work_answer_judge where work_id = #{workId} and user_id =#{userId}")
    List<JudgeAnswerViewBO> getStudentAnswerJudgeViewById(Integer userId, Integer workId);

    /**
     * 获取第几套填空题的答案
     * @param userId
     * @param workId
     * @return
     */
    @Select("select student_answer,right_answer,is_right from work_answer_fill where work_id = #{workId} and user_id =#{userId} and order_question = #{order} order by `order`")
    List<FillAnswerViewBO> getStudentAnswerFillViewById(Integer userId, Integer workId, int order);

    /**
     * 获取编程题答案
     * @param userId
     * @param workId
     * @return
     */
    @Select("select state from work_answer_encode where work_id = #{workId} and user_id =#{userId}")
    List<EncodeAnswerViewBO> getStudentAnswerEmptyViewById(Integer userId, Integer workId);
}
